if (!requireNamespace("BiocManager", quietly = TRUE))  
  install.packages("BiocManager")  
BiocManager::install("DESeq2")  
library(DESeq2)  
setwd("C:/Users/Rommel.Dks/Desktop/r")  
dataDESeq <- read.csv("mRNA_exprSet.csv", row.names = 1, check.names = FALSE) # 第一列是行名  
dataDESeq1 <- dataDESeq[rowSums(dataDESeq) != 0, ]  
# 创建colData，其中包含了样本的分组信息  
# 利用ID从第14和15个字符处提取信息  
colData1 <- data.frame(condition = substring(colnames(dataDESeq1), 14, 15))  
# 将"01"和"11"替换为"肿瘤"和"正常"  
colData1$condition <- ifelse(colData1$condition == "01", "肿瘤", ifelse(colData1$condition == "11", "正常", NA))  
# 检查是否所有条件都已经被正确替换  
# 创建DESeqDataSet对象  
dds <- DESeqDataSetFromMatrix(countData = as.matrix(dataDESeq1),  
                              colData = colData1,  
                              design = ~ condition)  
dds1 <- DESeq(dds)  
res <- results(dds1)  
write.csv(res, "6R1.csv", row.names = TRUE)  
res2 <- subset(res, padj < 0.05 & abs(log2FoldChange) > 1)  
write.csv(res2, "6R2.csv", row.names = TRUE)
